package com.xyhy.core.base.enums;

import com.xyhy.core.base.model.vo.EnumVO;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

public interface BaseTagEnum extends BaseEnum {

  String getTagType();

  static <T extends BaseTagEnum> List<EnumVO> getAllVO(T[] items) {
    return Arrays.stream(items).map(x -> new EnumVO().setName(x.name()).setText(x.getText()).setTagType(x.getTagType()))
            .collect(Collectors.toList());
  }

  static <T extends BaseTagEnum> EnumVO getVO(T item) {
    Function<T, EnumVO> fn = x -> new EnumVO().setName(x.name()).setText(x.getText()).setTagType(x.getTagType());
    return Optional.ofNullable(item).map(fn).orElse(null);
  }

}
